var getDetail = function(placeId){
	this.placeId = placeId;
	this.error = options.error;
	this.success = options.success;
        this.getDetail();
};

getDetail.prototype._success = function(data){
	if(typeof this.success == 'function') {
		this.success(data);
	}
};

getDetail.prototype._error = function(code, message){
	if(typeof this.error == 'function') {
		this.error(code, message);
	}
};

getDetail.prototype.check = function(nextStatement){
	var self = this;
	Mysql.query("SELECT COUNT(*) AS c1 FROM locationplace WHERE placeId="+Mysql.escape(self.placeId)+" LIMIT 1", function(error, results){
		if(error) {
			console.log('Mysql error: '+error);
			self._error(9999, 'Mysql error');
			return;
		}
		if(results[0].c1 == 0) {
			self._error(9999, 'Not found account');
			return;
		}
		nextStatement();
	});
};

getDetail.prototype.getDetail = function(){
	var self = this;
	self.check(function(){
		Mysql.query("SELECT locationplace.id,locationplace.placeId,locationcoordinate.id,locationcoordinate.lat,locationcoordinate.lng,place.id,place.name FROM locationplace JOIN locationcoordinate ON locationcoordinate.id = locationplace.id JOIN place ON place.id = locationplace.placeId WHERE locationplace.placeId="+Mysql.escape(self.placeId), function(error, results){
			if(error) {
				console.log('Mysql error: '+error);
				self._error(9999, 'Mysql error');
				return;
			}
                        var loc = 3.14 + ( lat + lng );
                        self._success({ id:results.id,name:results.name,location:loc });
		});
	});
};

module.exports = getDetail;